<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../css/singIn.css">
    <script src="../lib/jquery-1.12.4.js"></script>
</head>
<body>
    <div class="heard">
        <div class="logo">
            <img src="../images/mi-logo.png" alt="">
        </div>
        <div class="heard_r">
        <h2>小米商城</h2>
        <h3>让每个人都享受科技的乐趣</h3>
        </div>
    </div>
    <div class="sing-in">
        <img src="../images/1.jpg" alt="">
        <div class="sing_in_con">
            <h2>登录</h2>
            <form action="">
                <input type="text" class="sing_user" name="user" id="username" placeholder="邮箱/手机号码/小米ID">
                <input type="password" class="sing_password" name="pass" id="password" placeholder="密码">
                <input class="btnadpt" id="login-button" type="button" value="登录">
            </form>
        </div>
    </div>
    <script src="../js/public.js"></script>
    <script>
        $("#login-button").on("click",function(){
        //     jsonp('../php/singIn.php',
        //         function(data){
        //            if(data=='1'){
        //             　  window.location.href="http://localhost/src/pages/index.html";
        //                 if(localStorage.getItem('sign')){
        //                     window.localStorage.removeItem('sign');
        //                 }
        //                 var arr = {user:$('#username').val(),pass:$('#password').val(),static:true};//本地存储的值不能是字符串,但是我又想存呢
        //                 var str = JSON.stringify(arr)
        //                 localStorage.setItem('sign',str)
        //                 console.log(localStorage.getItem('sign'));
        //            }
        //            else{
        //                alert("你还未注册请进行注册");
        //                　window.location.href="http://localhost/src/pages/register.html";
        //            }
        //         },
        //         {
        //             username:$('#username').val(),
        //             password:$('#password').val(),
        //             bool:'1'
        //         }
        // )../php/singIn.php
        //     $.ajax({
        //         url:'http://localhost/src/php/singIn.php',
        //         type:'post',
        //         // dataType:'jsonp',
        //         data:{username:$('#username').val(),password:$('#password').val(),bool:'1'},
        //         success:function(data){
        //             console.log(data);
        //            if(data=='1'){
        //             　  window.location.href="http://localhost/src/pages/index.html";
        //                 if(localStorage.getItem('sign')){
        //                     window.localStorage.removeItem('sign');
        //                 }
        //                 var arr = {user:$('#username').val(),pass:$('#password').val(),static:true};//本地存储的值不能是字符串,但是我又想存呢
        //                 var str = JSON.stringify(arr)
        //                 localStorage.setItem('sign',str)
        //                 console.log(localStorage.getItem('sign'));
        //            }
        //            else{
        //                alert("你还未注册请进行注册");
        //                　window.location.href="http://localhost/src/pages/register.html";
        //            }
        //         },
        //         complete:function(){
        //             console.log('ajax完成了')
        //         },
        //         error:function(XMLHttpRequest, textStatus){
        //             console.log(XMLHttpRequest.status)
        //             console.log(textStatus)
        //             console.log('ajax发生错误了')
        //         },
        //         timeout:2000,
        //     })
        // })


        $.ajax({
                url:'http://localhost/src/php/singIn.php',
                dataType:'jsonp',
                data:{username:$('#username').val(),password:$('#password').val(),bool:'1'},
                success:function(data){
                    console.log(data);
                   if(data=='1'){
                    　  window.location.href="http://localhost/src/pages/index.html";
                        if(localStorage.getItem('sign')){
                            window.localStorage.removeItem('sign');
                        }
                        var arr = {user:$('#username').val(),pass:$('#password').val(),static:true};//本地存储的值不能是字符串,但是我又想存呢
                        var str = JSON.stringify(arr)
                        localStorage.setItem('sign',str)
                        // console.log(localStorage.getItem('sign'));
                   }
                   else{
                       alert("你还未注册请进行注册");
                       　window.location.href="http://localhost/src/pages/register.html";
                   }
                },
                complete:function(){
                    console.log('ajax完成了')
                },
                error:function(XMLHttpRequest, textStatus){
                    console.log(XMLHttpRequest.status)
                    console.log(textStatus)
                    console.log('ajax发生错误了')
                },
                timeout:2000,
            })
        })
    </script>
</body>
</html>